/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package xml2postgreconvertor;

import java.lang.String;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author swosh
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        String path = "/home/swosh/Documents/seznam ulic/ulice.xml";
        String nameRootWan = "obec";
        String attrRootWan = "nazev";
        String valRootWan = "Praha";
        String nameE1Wan = "cast";
        String attrE1Wan = "nazev";
        String nameE2Wan = "ulice";
        String attrE2Wan = "nazev";
        UliceDAO uliceDAO = new UliceDAO();
        List listStringArray3 = new XMLParser().get3XMLAttrValByRootAttrVal(path, nameRootWan, attrRootWan, valRootWan,
                nameE1Wan, attrE1Wan, nameE2Wan, attrE2Wan);
        List<Ulice> listUlice = new ArrayList<Ulice>();
        Set<String> setObec = new HashSet<String>();
        Set<String> setCastObce = new HashSet<String>();
        Set<String> setUlice = new HashSet<String>();


        for (Iterator it = listStringArray3.iterator(); it.hasNext();) {
            String[] arrayString = (String[]) it.next();
            Ulice ulice = new Ulice(arrayString[2], arrayString[1], arrayString[0].toString());
            listUlice.add(ulice);
        }
        listStringArray3.clear();
/*
        for (Iterator it = listUlice.iterator(); it.hasNext();) {
            Ulice ulice = (Ulice) it.next();
            if (!setObec.contains(ulice.getNazObce())) {
                setObec.add(ulice.getNazObce());
                try {
                    uliceDAO.saveObec(ulice);
                } catch (Exception ex) {
                    System.out.println(ex);
                }
            }

        }
        for (Iterator it = listUlice.iterator(); it.hasNext();) {
            Ulice ulice = (Ulice) it.next();
            if (!setCastObce.contains(ulice.getNazCastiObce())) {
                setCastObce.add(ulice.getNazCastiObce());
                try {
                    uliceDAO.saveCastObec(ulice);
                } catch (Exception ex) {
                    System.out.println(ex);
                }
            }

        }
        */
        for (Iterator it = listUlice.iterator(); it.hasNext();) {
            Ulice ulice = (Ulice) it.next();
            if (!setUlice.contains(ulice.getNazUlice())) {
                setUlice.add(ulice.getNazUlice());
                try {
                    uliceDAO.saveUlice(ulice);
                } catch (Exception ex) {
                    System.out.println(ex);
                }
            }

        }

    }
}
